/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.loseform.controller
 * FILE    NAME: LoseformDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.api.loseform.controller;

import java.math.BigInteger;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hero.common.web.context.UserContext;
import com.hero.core.constant.SysConstant;
import com.hero.core.entity.IPlatformUser;
import com.hero.core.entity.ResponseEntity;
import com.hero.core.util.DateUtils;
import com.hero.core.util.IdWorker;
import com.jodinfo.outmirror.api.loseform.entity.LoseformEntity;
import com.jodinfo.outmirror.api.loseform.service.LoseformBizService;



@Controller
@RequestMapping(value = "/LoseformAdmin")
public class LoseformController  {
	
@Resource(name="loseformBizService")
private LoseformBizService LoseformBizService;
/**
*  list数据源
* 
* */
@RequestMapping(value = "/List") 
@ResponseBody
public String LoseformList(LoseformEntity LoseformEntity) {
	if(LoseformEntity==null){
		LoseformEntity = new LoseformEntity();
		LoseformEntity.setPageIndex(SysConstant.DEFAULT_PAGEINDEX);
		LoseformEntity.setPageSize(SysConstant.DEFAULT_PAGESIZE);
	}
	LoseformEntity.setCurrentUser(UserContext.getUser());
	String str = LoseformBizService.queryListForPageLoseform(LoseformEntity);
	return str;
}
/**
* LoseformEntity List页面
* 
* */
@RequestMapping(value = "/ListPage")
public ModelAndView LoseformListPage(LoseformEntity LoseformEntity,HttpServletRequest request) {
	
	return new ModelAndView(returnPath("LoseformList"));
}
@RequestMapping(value = "/addLoseformEquipment")
public ModelAndView addLoseformEquipment(LoseformEntity LoseformEntity,HttpServletRequest request) {
	
	return new ModelAndView(returnPath("addLoseformEquipment"));
}

@RequestMapping(value = "/LoseFormSubmit")
public ModelAndView LoseFormSubmit(HttpServletRequest request) {
	IdWorker idWorker = new IdWorker(0,0);
	IPlatformUser user = (IPlatformUser)UserContext.getUser();
	String orgId = user.getOrgId();
	String orgName = user.getOrgName();
	return new ModelAndView(returnPath("LoseFormSubmit")).addObject("woNo","DS"+idWorker.nextId())
			.addObject("orgId",orgId)
			.addObject("orgName", orgName)
			.addObject("createUser",user.getName())
			.addObject("createTime",DateUtils.getCurrentTime());
}
@RequestMapping(value = "/editBarcode")
public ModelAndView editBarcode(HttpServletRequest request) {
	return new ModelAndView(returnPath("editBarcode"));
}
@RequestMapping(value = "/viewBarcode")
public ModelAndView viewBarcode(HttpServletRequest request) {
	return new ModelAndView(returnPath("viewBarcode"));
}
/**
* LoseformEntity详细页 
* */
@RequestMapping(value = "/EditPage")
public ModelAndView LoseformEditPage(LoseformEntity LoseformEntity) {
	
	return new ModelAndView(returnPath("LoseformAdd"));
}
/**
 * 查询LoseformEntity
 * 
 * */
@RequestMapping(value = "/queryByID")
public @ResponseBody String findLoseformData(HttpServletRequest request) {
	String id = request.getParameter("id");
	LoseformEntity LoseformEntity =  LoseformBizService.queryById(new BigInteger(id));
	return JSON.toJSONString(LoseformEntity); 
}

/**
 * 保存或更新Loseform 
 * 
 * */
@RequestMapping(value = "/saveLoseform")
public @ResponseBody String saveLoseformData(@RequestBody LoseformEntity LoseformEntity) {
	ResponseEntity rs = null;
	if(LoseformEntity!=null){
		LoseformEntity.setCurrentUser(UserContext.getUser());
		if(LoseformEntity.getId()!=null){
			rs = LoseformBizService.updateLoseform(LoseformEntity);
		}else{
			rs = LoseformBizService.addLoseform(LoseformEntity);
		}
	}
	return JSON.toJSONString(rs);
}

/**
 * 保存遗失单
 * @author cao.weiwei
 * @date 2017年7月12日 上午10:24:06
 * @param LoseformEntity
 * @return
 */
@RequestMapping(value = "/saveLoseformAndCode")
public @ResponseBody String saveLoseformAndCode(@RequestBody LoseformEntity LoseformEntity) {
	ResponseEntity rs = null;
	if(LoseformEntity!=null){
		LoseformEntity.setCurrentUser(UserContext.getUser());
		if(LoseformEntity.getId()!=null){
			rs = LoseformBizService.updateLoseformAndBarcode(LoseformEntity); 
		}else{
			rs = LoseformBizService.addLoseformAndBarcode(LoseformEntity); 
		}
	}
	return JSON.toJSONString(rs);
}
/**
 * 提交表单到OA
 * @author cao.weiwei
 * @date 2017年7月12日 上午9:32:04
 * @param LoseformEntity
 * @return
 */
@RequestMapping(value = "/submitLoseForm")
public @ResponseBody String submitLoseForm(@RequestBody LoseformEntity LoseformEntity) {
	ResponseEntity rs = null;
	if(LoseformEntity!=null){
		LoseformEntity.setCurrentUser(UserContext.getUser());
		LoseformEntity.setCurrentUserString(JSONObject.toJSONString((IPlatformUser)UserContext.getUser()));
		rs = LoseformBizService.submitLoseForm(LoseformEntity); 
	}
	return JSON.toJSONString(rs);
}
/**
 * 导出LoseformEntity
 * @author weiwei
 * @date 2015-7-09  下午2:13:28
 * @return
 */
@RequestMapping(value = "/exportLoseformExcel")
public void exportLoseformExcel(LoseformEntity LoseformEntity,HttpServletResponse response) {
	LoseformEntity.setCurrentUser(UserContext.getUser());
	LoseformBizService.exportLoseform(LoseformEntity, response);
}


 /**
 * 
 * 批量删除
 * @author weiwei
 * @date 2017年3月13日 下午2:48:57
 * @param LoseformEntity
 * @return
 */
@RequestMapping(value = "/batchDelLoseform")
public @ResponseBody String batchDelLoseform(LoseformEntity LoseformEntity) {
	ResponseEntity rs = null;
	rs = LoseformBizService.batchDelLoseform(LoseformEntity);
	return  JSON.toJSONString(rs);
}
/**
 * 定义
 * 
 */
private final String MODULE_PATH = "/loseform/";

//返回路径
private String returnPath(String jspName) {
	return MODULE_PATH + jspName;
}
}
